package com.demo;



import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast; 
 
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
 
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;

import java.util.Arrays;
import java.util.List; 
import com.yhao.floatwindow.FloatWindow;
 
public class MyActivity extends Activity implements View.OnClickListener {

    private ReactInstanceManager mReactInstanceManager;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        
      

        super.onCreate(savedInstanceState); 

        setContentView(createView());
        ImageView imageView = new ImageView(getApplicationContext());
        imageView.setImageResource(R.drawable.icon);

        FloatWindow
            .with(getApplicationContext())
            .setView(imageView) 
            .setTag("example") 
            .build()
            .show();
    }

    private View createView() {
        LinearLayout ll= new LinearLayout(this);
        ll.setGravity(Gravity.CENTER);
        ll.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        // 设置文字
        TextView mTextView = new TextView(this);
        mTextView.setText("hello world"); 
        Button mButton =new Button(this);
        mButton.setText("点击回RN页面");
        mButton.setOnClickListener(this); 
        LinearLayout.LayoutParams mLayoutParams = new LinearLayout.LayoutParams(  ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        // 在父类布局中添加它，及布局样式
        ll.addView(mTextView, mLayoutParams);
        ll.addView(mButton, mLayoutParams);  
        return ll;

    } 

    @Override
    public void onClick(View v) {
 
        mReactInstanceManager = ((MainApplication) getApplication()).getReactNativeHost().getReactInstanceManager();        
        startActivity(new Intent(this, MainActivity.class));
        recreate(); 
    }

     @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mReactInstanceManager != null) {
            mReactInstanceManager.onHostDestroy();
        }
    }
}


